home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 701-725 / 708 / intuisup / intuisup42.lha / Intuisup / source.lha / Library / libstartup.asm < prev    next >
Assembly Source File  |  1992-04-20  |  9KB  |  367 lines

  1.  * $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: libstartup.asm
  6.  *    Created ..: Sunday 22-Dec-91 20:35:08
  7.  *    Revision .: 0
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    22-Dec-91   Torsten Jürgeleit      Created this file!
  12.  *
  13.  ****************************************************************************
  14.  *
  15.  *    Startup code for IntuiSup library
  16.  *
  17.  * $Revision Header ********************************************************
  18.  
  19. ;---------------------------------------------------------------------------
  20. ; Includes
  21. ;---------------------------------------------------------------------------
  22.  
  23.     NOLIST
  24.     INCLUDE    <exec/types.i>
  25.     INCLUDE <exec/libraries.i>
  26.     INCLUDE <exec/initializers.i>
  27.     INCLUDE <exec/resident.i>
  28.     INCLUDE    "libdata.i"
  29.     LIST
  30.  
  31. ;---------------------------------------------------------------------------
  32. ; External definitions
  33. ;---------------------------------------------------------------------------
  34.  
  35.     XDEF    .begin
  36.     XDEF    _LibOpen
  37.     XDEF    _LibClose
  38.     XDEF    _LibExpunge
  39.     XDEF    _LibNull
  40.     XDEF    _geta4
  41.     XDEF    _SysBase
  42.     XDEF    _GfxBase
  43.     XDEF    _IntuitionBase
  44.     XDEF    _DiskfontBase
  45.     XDEF    _LayersBase
  46.  
  47. ;---------------------------------------------------------------------------
  48. ; External references
  49. ;---------------------------------------------------------------------------
  50.  
  51.     XREF    __H1_org
  52.     XREF    _FuncTable
  53.  
  54. ;---------------------------------------------------------------------------
  55. ; Support macros
  56. ;---------------------------------------------------------------------------
  57.  
  58. CALL    MACRO
  59.     XREF    \1
  60.     jsr    \1
  61.     ENDM
  62.  
  63. CALLSYS    MACRO
  64.     XREF    _LVO\1
  65.     jsr    _LVO\1(a6)
  66.     ENDM
  67.  
  68. PUSH    MACRO
  69.     movem.l    \1,-(sp)
  70.     ENDM
  71.  
  72. PULL    MACRO
  73.     movem.l    (sp)+,\1
  74.     ENDM
  75.  
  76. ;---------------------------------------------------------------------------
  77. ; First executable location -> do nothing
  78. ;---------------------------------------------------------------------------
  79.  
  80.     SECTION IntuitionSupport,CODE
  81. .begin:
  82.     moveq    #0,d0
  83.     rts
  84.  
  85. ;---------------------------------------------------------------------------
  86. ; RomTag structure
  87. ;---------------------------------------------------------------------------
  88.  
  89. RomTag:                ; STRUCTURE RT,0
  90.     dc.w    RTC_MATCHWORD    ;    UWORD RT_MATCHWORD
  91.     dc.l    RomTag        ;    APTR  RT_MATCHTAG
  92.     dc.l    EndCode        ;    APTR  RT_ENDSKIP
  93.     dc.b    RTF_AUTOINIT    ;    UBYTE RT_FLAGS
  94.     dc.b    VERSION        ;    UBYTE RT_VERSION
  95.     dc.b    NT_LIBRARY    ;    UBYTE RT_TYPE
  96.     dc.b    PRIORITY    ;    BYTE  RT_PRI
  97.     dc.l    LibName        ;    APTR  RT_NAME
  98.     dc.l    LibID        ;    APTR  RT_IDSTRING
  99.     dc.l    InitTable    ;    APTR  RT_INIT
  100.  
  101. ;---------------------------------------------------------------------------
  102. ; Library strings
  103. ;---------------------------------------------------------------------------
  104.  
  105. LibName:    LIB_NAME
  106. LibTag:        dc.b    0,"$VER:"
  107. LibID:        LIB_ID
  108.         INCLUDE <ram:compile_date.i>
  109. GfxName:    dc.b    "graphics.library",0
  110. IntuitionName:    dc.b    "intuition.library",0
  111. DiskfontName:    dc.b    "diskfont.library",0
  112. LayersName:    dc.b    "layers.library",0
  113.     EVEN
  114.  
  115. ;---------------------------------------------------------------------------
  116. ; Library tables
  117. ;---------------------------------------------------------------------------
  118.  
  119. InitTable:
  120.     dc.l    LIB_SIZEOF    ; size of library base data space
  121.     dc.l    _FuncTable    ; pointer to function initializers
  122.     dc.l    DataTable    ; pointer to data initializers
  123.     dc.l    InitRoutine    ; routine to run
  124.  
  125. DataTable:
  126.     INITBYTE    LN_TYPE,NT_LIBRARY
  127.     INITLONG    LN_NAME,LibName
  128.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  129.     INITWORD    LIB_VERSION,VERSION
  130.     INITWORD    LIB_REVISION,REVISION
  131.     INITLONG    LIB_IDSTRING,LibID
  132.     dc.l        0
  133.  
  134. ;---------------------------------------------------------------------------
  135. ; Library init routine
  136. ;
  137. ; Input: d0 = library ptr       Return: d0 = library ptr or NULL if error
  138. ;     a0 = seglist ptr
  139. ;     a6 = SysBase
  140. ;---------------------------------------------------------------------------
  141.  
  142. InitRoutine:
  143.     PUSH    d2/a2-a4
  144.  
  145.     ; --- save library ptr
  146.     move.l    d0,a2
  147.  
  148.     ; --- init important ptrs
  149.     bsr    _geta4            ; a4 := data segment ptr
  150.     lea    SegList,a3        ; a3 := start of ptr buffer
  151.     move.l    a0,(a3)+        ; init SegList
  152.     move.l    a6,(a3)+        ; init _SysBase
  153.  
  154.     ; --- open libraries
  155.     lea    GfxName(pc),a1
  156.     moveq    #0,d0
  157.     CALLSYS    OpenLibrary
  158.     move.l    d0,(a3)+
  159.     beq    InitRoutine_Error
  160.  
  161.     lea    IntuitionName(pc),a1
  162.     moveq    #0,d0
  163.     CALLSYS    OpenLibrary
  164.     move.l    d0,(a3)+
  165.     beq    InitRoutine_CloseGfxLib
  166.  
  167.     lea    DiskfontName(pc),a1
  168.     moveq    #0,d0
  169.     CALLSYS    OpenLibrary
  170.     move.l    d0,(a3)+
  171.     beq    InitRoutine_CloseIntuitionLib
  172.  
  173.     lea    LayersName(pc),a1
  174.     moveq    #0,d0
  175.     CALLSYS    OpenLibrary
  176.     move.l    d0,(a3)+
  177.     beq    InitRoutine_CloseDiskfontLib
  178.  
  179.     ; --- call library specific init routine
  180.     PUSH    a2-a4/a6
  181.     CALL    _LibInit
  182.     PULL    a2-a4/a6
  183.     tst.w    d0            ; check return code (BOOL)
  184.     beq    InitRoutine_CloseLayersLib
  185.  
  186.     move.l    a2,d0            ; set return code -> ok
  187.  
  188. InitRoutine_Exit:
  189.     PULL    d2/a2-a4
  190.     rts
  191.  
  192. InitRoutine_CloseLayersLib:
  193.     moveq    #3,d2
  194.     bra    InitRoutine_CloseLibs
  195.  
  196. InitRoutine_CloseDiskfontLib:
  197.     moveq    #2,d2
  198.     bra    InitRoutine_CloseLibs
  199.  
  200. InitRoutine_CloseIntuitionLib:
  201.     moveq    #1,d2
  202.     bra    InitRoutine_CloseLibs
  203.  
  204. InitRoutine_CloseGfxLib:
  205.     moveq    #0,d2
  206.     bra    InitRoutine_CloseLibs
  207.  
  208. InitRoutine_CloseLibs:
  209.     move.l    -(a3),a1
  210.     CALLSYS    CloseLibrary
  211.     dbra    d2,InitRoutine_CloseLibs
  212.  
  213. InitRoutine_Error:
  214.     moveq    #0,d0            ; set return code -> error
  215.     bra    InitRoutine_Exit
  216.  
  217. ;---------------------------------------------------------------------------
  218. ; Library open routine
  219. ;
  220. ; Input: d0 = version        Return: d0 = library ptr or NULL if error
  221. ;     a6 = library ptr
  222. ;---------------------------------------------------------------------------
  223.  
  224. _LibOpen:
  225.     ; --- mark us as having another opener
  226.     addq.w    #1,LIB_OPENCNT(a6)
  227.  
  228.     ; --- prevent delayed expunges
  229.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  230.  
  231.     move.l    a6,d0            ; set return code -> ok
  232.     rts
  233.  
  234. ;---------------------------------------------------------------------------
  235. ; Library close routine
  236. ;
  237. ; Input: a6 = library ptr    Return: d0 = NULL or seglist ptr if expunge
  238. ;---------------------------------------------------------------------------
  239.  
  240. _LibClose:
  241.     ; --- set the return value for no expunge
  242.     moveq    #0,d0
  243.  
  244.     ; --- mark us as having one fewer openers
  245.     subq.w    #1,LIB_OPENCNT(a6)
  246.  
  247.     ; --- see if there is anyone left with us open
  248.     bne    LibClose_Exit
  249.  
  250.     ; --- see if we have a delayed expunge pending
  251.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  252.     beq    LibClose_Exit
  253.  
  254.     ; --- do the expunge
  255.     bsr    _LibExpunge
  256.  
  257. LibClose_Exit:
  258.     rts
  259.  
  260. ;---------------------------------------------------------------------------
  261. ; Library open routine
  262. ;
  263. ; Input: a6 = library ptr    Return: d0 = NULL or seglist ptr if expunge
  264. ;---------------------------------------------------------------------------
  265.  
  266. _LibExpunge:
  267.     PUSH    d2/a4-a6
  268.  
  269.     ; --- init some regs
  270.     bsr    _geta4            ; a4 := data segment ptr
  271.     move.l    a6,a5            ; a5 := library ptr
  272.     move.l    _SysBase,a6        ; a6 := SysBase
  273.    
  274.     ; --- see if anyone has us open
  275.     tst.w    LIB_OPENCNT(a5)
  276.     beq    LibExpunge_DoExpunge
  277.  
  278.     ; --- it is still open.  set the delayed expunge flag
  279.     bset    #LIBB_DELEXP,LIB_FLAGS(a5)
  280.     moveq    #0,d0            ; set reurn code -> no expunge
  281.     bra    LibExpunge_Exit
  282.  
  283. LibExpunge_DoExpunge:
  284.     ; --- unlink from library list
  285.     move.l    a5,a1
  286.     CALLSYS    Remove
  287.    
  288.     ; --- library specific expunge routine
  289.     PUSH    a4-a6
  290.     CALL    _LibFree
  291.     PULL    a4-a6
  292.  
  293.     ; --- free our memory
  294.     moveq    #0,d0
  295.     move.l    a5,a1
  296.     move.w    LIB_NEGSIZE(a5),d0
  297.     sub.l    d0,a1
  298.     add.w    LIB_POSSIZE(a5),d0
  299.     CALLSYS    FreeMem
  300.  
  301.     ; --- close libraries
  302.     lea    _GfxBase,a5
  303.     moveq    #3,d2
  304.  
  305. LibExpunge_CloseLoop:
  306.     move.l    (a5)+,a1
  307.     CALLSYS    CloseLibrary
  308.     dbra    d2,LibExpunge_CloseLoop
  309.  
  310.     ; --- set up our return value
  311.     move.l    SegList,d0
  312.  
  313. LibExpunge_Exit:
  314.     PULL    d2/a4-a6
  315.     rts
  316.  
  317. ;---------------------------------------------------------------------------
  318. ; Library null routine
  319. ;
  320. ; Input: a6 = library ptr
  321. ;---------------------------------------------------------------------------
  322.  
  323. _LibNull:
  324.     moveq    #0,d0
  325.     rts
  326.  
  327. ;---------------------------------------------------------------------------
  328. ; Init data segment ptr a4 - needed for small data memory model
  329. ;---------------------------------------------------------------------------
  330.  
  331. _geta4:
  332.     FAR    CODE
  333.     FAR    DATA
  334.  
  335.     lea    __H1_org+32766,a4
  336.  
  337.     NEAR    DATA
  338.     NEAR    CODE
  339.     rts
  340.  
  341. ;---------------------------------------------------------------------------
  342. ; Skip label for RomTag
  343. ;---------------------------------------------------------------------------
  344.  
  345. EndCode:
  346.  
  347.     SECTION IntuitionSupport,DATA
  348.  
  349. ;---------------------------------------------------------------------------
  350. ; Important ptrs -> init by Init
  351. ;---------------------------------------------------------------------------
  352.     
  353. SegList:
  354.     dc.l    0
  355. _SysBase:
  356.     dc.l    0
  357. _GfxBase:
  358.     dc.l    0
  359. _IntuitionBase:
  360.     dc.l    0
  361. _DiskfontBase:
  362.     dc.l    0
  363. _LayersBase:
  364.     dc.l    0
  365.  
  366.     END
  367.